using System;
using System.Runtime.InteropServices;

using Pegasus.Windows.API.Enumerations;
using Pegasus.Windows.API.Interfaces;
using Pegasus.Windows.API.Structures;

namespace Pegasus.Windows.API
{
	/// <summary>
	/// This class is the p/invoke Windows API for the shell32.dll
	/// </summary>
	public static class Shell32
	{
		/// <summary>
		/// Retrieves the IShellFolder interface for the desktop folder, which is the root of the Shell's namespace.
		/// </summary>
		/// <param name="shellFolder">The pointer to the IShellFolder interface.</param>
		/// <returns>WindowsConst.S_OK if succ</returns>
		[DllImport( "shell32.dll" )]
		public static extern uint SHGetDesktopFolder( out IShellFolder shellFolder );

		/// <summary>
		/// Retrieves information about an object in the file system, such as a file, a folder, a directory, or a drive root.
		/// </summary>
		/// <param name="pidl">The pidl.</param>
		/// <param name="dwFileAttributes">The dw file attributes.</param>
		/// <param name="sfi">The sfi.</param>
		/// <param name="cbFileInfo">The cb file info.</param>
		/// <param name="uFlags">The u flags.</param>
		/// <returns></returns>
		[DllImport( "shell32", EntryPoint = "SHGetFileInfo", ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true )]
		public static extern uint SHGetFileInfo( IntPtr pidl, FILE_ATTRIBUTE dwFileAttributes, ref SHFILEINFO sfi, int cbFileInfo, SHGFI uFlags );

		/// <summary>
		/// Retrieves information about an object in the file system, such as a file, a folder, a directory, or a drive root.
		/// </summary>
		/// <param name="pszPath">The path to the file to get the information for.</param>
		/// <param name="dwFileAttributes">The dw file attributes.</param>
		/// <param name="sfi">The sfi.</param>
		/// <param name="cbFileInfo">The cb file info.</param>
		/// <param name="uFlags">The u flags.</param>
		/// <returns></returns>
		[DllImport( "shell32", EntryPoint = "SHGetFileInfo", ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true )]
		public static extern uint SHGetFileInfo( string pszPath, FILE_ATTRIBUTE dwFileAttributes, ref SHFILEINFO sfi, int cbFileInfo, SHGFI uFlags );

		/// <summary>
		/// Get the system image list.
		/// </summary>
		/// <param name="imageList">The image list.</param>
		/// <param name="riid">The riid.</param>
		/// <param name="pil">The pil.</param>
		/// <returns></returns>
		[DllImport( "shell32", EntryPoint = "SHGetImageList", ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true )]
		public static extern uint SHGetImageList( SHIL imageList, [MarshalAs( UnmanagedType.LPStruct )] Guid riid, ref IntPtr pil );

		/// <summary>
		/// Retrieves pidl of special folder
		/// </summary>
		/// <param name="hwndOwner">The HWND owner.</param>
		/// <param name="nFolder">The predefined csidl of the folder.</param>
		/// <param name="pidl">The pidl.</param>
		/// <returns></returns>
		[DllImport( "Shell32", EntryPoint = "SHGetSpecialFolderLocation", ExactSpelling = true, CharSet = CharSet.Ansi, SetLastError = true )]
		public static extern uint SHGetSpecialFolderLocation( IntPtr hwndOwner, CSIDL nFolder, out IntPtr pidl );
	}
}
